package com.tongxin.van.frameworkcanary.utils;

import java.text.DecimalFormat;

/**
 *
 * author: VanyLiu
 * email: 13212674795@163.com
 * description:数据格式工具类
 *
**/

public class FormatUtils {


    public static String formatPrice(String priceStr) {
        try {
            double price = Double.parseDouble(priceStr);
            return formatPrice(price) + "元";
        } catch (Exception e) {
            return "0.00元";
        }
    }

    public static String formatPrice2(String priceStr) {
        try {
            double price = Double.parseDouble(priceStr);
            return formatPrice(price);
        } catch (Exception e) {
            return "0.00";
        }
    }

    public static String formatPrice3(String priceStr) {
        try {
            double price = Double.parseDouble(priceStr);
            return formatPrice(price);
        } catch (Exception e) {
            return "0";
        }
    }

    public static String formatPrice(double price) {
        if (price == 0) {
            return "0.00";
        }
        DecimalFormat dformat = new DecimalFormat("#0.00");
        return dformat.format(price);
    }

    public static String formatPrice2(double price) {
        if (price == 0) {
            return "¥0.00";
        }
        DecimalFormat dformat = new DecimalFormat("#0.00");
        return "¥" + dformat.format(price);
    }

    public static String formatPrice3(double price) {
        if (price == 0) {
            return "¥0";
        }
        DecimalFormat dformat = new DecimalFormat("#0");
        return "¥" + dformat.format(price);
    }

    public static String formatPrice4(double price) {
        if (price == 0) {
            return "0";
        }
        DecimalFormat dformat = new DecimalFormat("#0");
        return dformat.format(price);
    }
}
